﻿using RpcHelper;
using RpcManageClient;
using RpcModel;
using RpcModel.Model;
using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{
        internal class ServerDictateLimitCollect : BasicCollect<ServerDictateLimitDAL>, IServerDictateLimitCollect
        {
                private IRpcServerCollect _RpcServer => this.GetCollect<IRpcServerCollect> ();
                public long AddDictateLimit (AddDictateLimit add)
                {
                        long id = this.BasicDAL.Add (add);
                        this._RpcServer.RefreshDictateLimit (add.ServerId, add.Dictate);
                        return id;
                }
                public ServerDictateLimitData GetDictateLimit (long id)
                {
                        ServerDictateLimitData limit = this.BasicDAL.Get (id);
                        if (limit == null)
                        {
                                throw new ErrorException ("rpc.dictate.not.find");
                        }
                        return limit;
                }
                public void DropDictateLimit (long id)
                {
                        ServerDictateLimitData limit = this.GetDictateLimit (id);
                        this.BasicDAL.Delete (limit.Id);
                        this._RpcServer.RefreshDictateLimit (limit.ServerId, limit.Dictate);
                }
                public void SetDictateLimit (long id, ServerDictateLimit limit)
                {
                        ServerDictateLimitData data = this.GetDictateLimit (id);
                        this.BasicDAL.Set (id, limit);
                        this._RpcServer.RefreshDictateLimit (data.ServerId, limit.Dictate);
                }
                public ServerDictateLimitData[] Query (long serverId, string dictate, IBasicPage paging, out long count)
                {
                        return this.BasicDAL.Query (serverId, dictate, paging, out count);
                }
        }
}
